package org.gnyxy.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.gnyxy.dto.GoodsSalesDTO;
import org.gnyxy.dto.OrdersPageQueryDTO;
import org.gnyxy.entity.Orders;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrdersMapper {
//    @Insert("insert into orders(user_id, consignee, number, status, address_id, order_time, checkout_time, pay_status," +
//            " amount, remark, phone, address, cancel_reason, rejection_reason, cancel_time, delivery_status, " +
//            "delivery_time, pack_amount, tableware_number, tableware_status, deleted) VALUES " +
//            "(#{userId},#{consignee},#{number},#{status},#{addressId},#{orderTime},#{checkoutTime},#{payStatus}" +
//            "#{amount})")
    void insert(Orders orders);

    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String outTradeNo, Long userId);

    void update(Orders orders);

    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);

    @Select("select * from orders where number = #{orderNumber} and deleted = 0")
    Orders getByOrderNumber(String orderNumber);

    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);


    Double sumByMap(Map map);

    Integer countByMap(Map map);

    List<GoodsSalesDTO> getSalesTop10(LocalDateTime beginTime, LocalDateTime endTime);
}
